<?php

use yii\db\Migration;

/**
 * Class m200619_102017_equ
 */
class m200619_102017_equ extends Migration
{



    // Use up()/down() to run migration code without a transaction.
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%equ_line}}', [
            'id'               => $this->integer(),
            'name'             => $this->string()->notNull()->defaultValue(''),
            'status'           => $this->tinyInteger()->notNull()->defaultValue(1),
            'created_at'       => $this->integer()->notNull(),
            'updated_at'       => $this->integer()->notNull(),
            'PRIMARY KEY ([[id]])',
        ], $tableOptions);

        $this->createTable('{{%equ_station}}', [
            'id'               => $this->integer(),
            'line_id'          => $this->integer(),
            'name'             => $this->string()->notNull()->defaultValue(''),
            'status'           => $this->tinyInteger()->notNull()->defaultValue(1),
            'created_at'       => $this->integer()->notNull(),
            'updated_at'       => $this->integer()->notNull(),
            'PRIMARY KEY ([[id]])',
        ], $tableOptions);

        $this->createTable('{{%equ_lane}}', [
            'id'               => $this->integer(),
            'station_id'       => $this->integer(),
            'name'             => $this->string()->notNull()->defaultValue(''),
            'status'           => $this->tinyInteger()->notNull()->defaultValue(1),
            'created_at'       => $this->integer()->notNull(),
            'updated_at'       => $this->integer()->notNull(),
            'PRIMARY KEY ([[id]])',
        ], $tableOptions);

        $this->createTable('{{%equ_computer}}', [
            'id'               => $this->integer(),
            'station_id'       => $this->integer(),
            'line_id'          => $this->integer(),
            'name'             => $this->string()->notNull()->defaultValue(''),
            'ip'               => $this->string()->notNull()->defaultValue(''),
            'status'           => $this->tinyInteger()->notNull()->defaultValue(1),
            'created_at'       => $this->integer()->notNull(),
            'updated_at'       => $this->integer()->notNull(),
            'PRIMARY KEY ([[id]])',
        ], $tableOptions);


    }

    public function down()
    {
        $this->dropTable('{{%equ_line}}');
        $this->dropTable('{{%equ_station}}');
        $this->dropTable('{{%equ_lane}}');

        return false;
    }

    /**
     * {@inheritdoc}
     */
    /*public function safeUp()
    {

    }*/

    /**
     * {@inheritdoc}
     */
    /* public function safeDown()
     {
         echo "m200619_102017_equ cannot be reverted.\n";

         return false;
     }*/

}
